package com.qs.eggs.view.recharge.activity;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;

import com.qs.eggs.R;
import com.qs.eggs.adapter.BaseTabIndicatorAdapter1;
import com.qs.eggs.base.activity.BaseActivity;
import com.qs.eggs.view.recharge.fragment.DanshiFragment;
import com.qs.eggs.view.recharge.fragment.OnlineFragment;
import com.shizhefei.view.indicator.FixedIndicatorView;
import com.shizhefei.view.indicator.IndicatorViewPager;
import com.shizhefei.view.indicator.slidebar.ColorBar;
import com.shizhefei.view.indicator.transition.OnTransitionTextListener;

import java.util.ArrayList;

public class RechargeActivity extends BaseActivity {
    private FixedIndicatorView indicator;
    private IndicatorViewPager indicatorViewPager;
    private String[] tabName = new String[] {"在线充值","蛋事卡充值"};
    private ArrayList<Fragment> fmList;
    private ViewPager viewPager;
    @Override
    protected int getContentView() {
        return R.layout.activity_recharge;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        indicator=(FixedIndicatorView)findViewById(R.id.guide_indicator);
        viewPager=(ViewPager)findViewById(R.id.guide_viewPager);
        fmList=new ArrayList<>();
        fmList.add(new OnlineFragment());
        fmList.add(new DanshiFragment());
        // 将viewPager和indicator使用
        indicator.setItemClickable(false);
        indicatorViewPager = new IndicatorViewPager(indicator, viewPager,true);
        ViewPagerSetting();
    }

    @Override
    protected void initData() {
        super.initData();
    }


    private void ViewPagerSetting() {

        // 指示条
        indicator.setScrollBar(new ColorBar(this, ContextCompat.getColor(this,R.color.tab_main), 2));
        // 未选中字体大小
        float unSelectSize = 18;
        // 选中字体大小
        float selectSize = unSelectSize * 1.0f;
        // 未选中的颜色
        int unSelectColor = Color.parseColor("#bbbbbb");
        // 选中时的颜色
        int selectColor = ContextCompat.getColor(this,R.color.tab_main);

        // 设置tab字体的变化
        indicator.setOnTransitionListener(new OnTransitionTextListener(
                selectSize, unSelectSize, selectColor, unSelectColor));

        viewPager.setOffscreenPageLimit(2);
        indicatorViewPager = new IndicatorViewPager(indicator, viewPager);
        // 设置适配器
        indicatorViewPager.setAdapter(new BaseTabIndicatorAdapter1(getSupportFragmentManager(),this,fmList,tabName));
        indicatorViewPager.setOnIndicatorPageChangeListener(new IndicatorViewPager.OnIndicatorPageChangeListener() {
            @Override
            public void onIndicatorPageChange(int preItem, int currentItem) {
                viewPager.setCurrentItem(currentItem);
            }
        });
    }
}
